/*******************************************************************
 * (c) Arphen Lin, arphenlin@gmail.com
 ********************************************************************/
// ==UserScript==
// @name		  YFNBA
// @description   Yahoo! Fantasy NBA
// @version				2007-11-21
// @namespace
// @include	   http://basketball.fantasysports.yahoo.com/nba/*
// @exclude
// ==/UserScript==

function gm_getHtml(sUrl, callback, userData){
	var hash = Math.random().toString().substring(2, 20);
	sUrl += (sUrl.indexOf('?')>0? '&':'?') + 'hash=' + hash;

	GM_xmlhttpRequest({
		method: 'GET',
		url: encodeURI(sUrl),
		headers:{
			'User-Agent':'monkeyagent',
			'Accept':'text/monkey,text/xml'
		},
		data: userData,
		onload: function(r){
			var html = new String(r.responseText);
			html = html.replace(/\n/g, ' ').replace(/^.*<body[^>]*>(.*)<\/body>.*$/gi, '$1');	// get data inside <body>...</body>
			callback(html, this.data);
		}
	});
}


function loadScript(scriptURLs) {
	var head = document.getElementsByTagName('head')[0];
	for(i in scriptURLs){
		var scriptElem = document.createElement('SCRIPT');
		scriptElem.setAttribute('type', 'text/javascript');
		scriptElem.setAttribute('language', 'javascript');
		scriptElem.setAttribute('src', scriptURLs[i]);
		head.appendChild(scriptElem);
	}
	waitScript();
}


loadScript([
	'http://yfnba.googlecode.com/svn/trunk/jquery.pack.js',
	'http://yfnba.googlecode.com/svn/trunk/gmlib.pack.js',
	'http://yfnba.googlecode.com/svn/trunk/yfnba_2007.pack.js'
]);


function waitScript(){
	if(typeof unsafeWindow.jQuery == 'undefined' ||
		typeof unsafeWindow.gm == 'undefined'||
		typeof unsafeWindow.YFNBA == 'undefined') {
		window.setTimeout(waitScript, 1000);
	} else {
		unsafeWindow.YFNBA.main(gm_getHtml, myOptions);		// very tricky here!
	}
}

// --------------------------------------------------------------
// Please set your league/team information
// --------------------------------------------------------------
// Example:
/*
myOptions = {
	refreshInterval: 60,		// auto-refresh interval, >= 60(s), or you would be blocked by yahoo!
	leagueInfo: [	
		{ lid: 20332,					// League ID
			tid: 9,							// Team ID
			tname: 'myh2h-1'		// Team Name
		},
		{ lid: 35251,
			tid: 11,
			tname: 'myh2h-2'
		},
		{ lid: 7924,
			tid: 8,
			tname: 'myroto-1'
		},
		{ lid: 1150,
			tid: 9,
			tname: 'myroto-2'
		}
	]
};

*/

myOptions = {

};